#include <iostream>
#include <bits/stdc++.h>

using namespace std;

struct bangpai
{
    string N;//name
    string P;//position
    int B;//bang gong
    int G;//grade
}b[200];

vector<int> a;

int t[5];


int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)//cin
    {
        cin>>b[i].N>>b[i].P>>b[i].B>>b[i].G;

        if(b[i].P=="BangZhu") t[1]=i;
        if(b[i].P=="FuBangZhu") {if(t[2]==0) t[2]=i;else t[3]=i;}

    }

    int o=t[2],u=t[3];//sort_2.1
    if(b[u].G>b[o].G) t[2]=u,t[3]=o;

    for(int i=1;i<=n;++i)//sort_1
    {

        if(a.empty()) a.push_back(i);
        else {
                int p=a.end(),q=a.begin();

            if(b[i].B<=b[p].B) a.push_back(i);

           else if(b[i].B<=b[q].B)  a.insert(a.begin(),i);

           else {

            for(int j=0;j<a.size();j++)
            {
                int g=a[j],h=a[j+1];
                if(b[i].B<=b[g].B&&b[i].B>b[h].B)
                    a.insert(a.begin()+j+1,i);
                break;
            }
           }
        }
    }

    int order=1;
    for(int i=0;i<a.size();++i)//assign
    {
        int u=a[i];
        if(b[u].P!="BangZhu"||b[u].p!="FuBangZhu"||b[u].N!="absi2011")
        {
            if(order<=2) b[u].P="HuFa",order++;

            else if(order>2&&order<=6)
                b[u].P="ZhangLao",order++;

            else if(order>6&&order<=13)
                b[u].P="TangZhu",order++;

            else if(order>13&&order<=38)
                b[u].P="JingYing",order++;

            else
                b[u].P="BangZhong",order++;

        }
        else continue;
    }


    for{int i=1;i<=3;++i}
    {
        int s=t[i];
        cout<<b[s].N<<" "<<b[s].P<<" "<<b[s].G<<endl;
    }
    for(int i=1;i<=n;++i)
    {

    }
    return 0;

}
